package com.ohimy.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 * 群组信息封装类
 * 
 * @author Tony Tang
 * @version 1.0
 */
@Entity
@MappedSuperclass
@Table(name = "ohimy_group")
public class Group implements Serializable {

	private static final long serialVersionUID = -3044073975954218548L;

	private long id;

	private GroupCate groupCate; // 所属分类ID

	private String name; // 群组名称

	private String description; // 群组描述

	private long founder; // 创建人Id

	private String groupHeader; // 群组头像

	private long number; // 会员人数(不映射入数据库)

	private Date created; // 创建时间

	private List<GroupUserShip> groupUserShip;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@ManyToOne(cascade = CascadeType.PERSIST, optional = false)
	public GroupCate getGroupCate() {
		return groupCate;
	}

	public void setGroupCate(GroupCate groupCate) {
		this.groupCate = groupCate;
	}

	@Column(name = "_name", length = 64, unique = true)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Lob
	@Column(name = "_description")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "_founder")
	public long getFounder() {
		return founder;
	}

	public void setFounder(long founder) {
		this.founder = founder;
	}

	@Column(name = "_header", length = 64)
	public String getGroupHeader() {
		return groupHeader;
	}

	public void setGroupHeader(String groupHeader) {
		this.groupHeader = groupHeader;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "_created", updatable = false)
	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	@Transient
	public long getNumber() {
		return number;
	}

	public void setNumber(long number) {
		this.number = number;
	}

	@OneToMany(mappedBy = "group")
	public List<GroupUserShip> getGroupUserShip() {
		return groupUserShip;
	}

	public void setGroupUserShip(List<GroupUserShip> groupUserShip) {
		this.groupUserShip = groupUserShip;
	}

}
